
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:reabampos/src/reabam/operation/db/objectbox.dart';
import 'package:reabampos/src/reabam/operation/rb_api.dart';
import 'package:reabampos/src/reabam/operation/rb_config.dart';
import 'package:reabampos/src/reabam/ui_self_service/pagestate_ss_home_index.dart';
import 'package:reabampos/src/reabam/ui_self_service/pagestate_ss_login.dart';
import 'package:reabampos/src/reabam/ui_self_service/shoppingcart/pagestate_ss_manual_input_gooditem_barcode_search.dart';
import 'package:reabampos/src/reabam/utils/rb_business.dart';
import 'package:reabampos/src/reabam/utils/rb_color.dart';
import 'package:reabampos/src/reabam/utils/rb_widget_ss.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_string.dart';
import 'package:xsdk_flutter/xsdk/xsdk_flutter_package.dart';

/*
支付结果
 */
class PageStateSelfServicePayResult extends XPageState{

  bool isSucceed;

  PageStateSelfServicePayResult(this.isSucceed);

  @override
  void onStart() {


  }

  @override
  Widget getBodyWidget(BuildContext context) {
    return XWidgetUtils.getLayoutContainer(
        alignment: Alignment.topCenter,
        padding: XWidgetUtils.getEdgeInsets(0, 477, 0, 0),
        child: XWidgetUtils.getLayoutColumn(
            crossAxisAlignment :CrossAxisAlignment.center,
            children: [
              XImageUtils.getImageWidgetWithAsset(
                isSucceed?'ss_pay_result_1.png':'ss_pay_reslut_2.png',
                width: 161,
                height: 160,
              ),
              XWidgetUtils.getWidgetText(
                  isSucceed?'支付成功':'支付失败',
                  style: XStyleUtils.getTextStyle(
                      fontSize: 60,
                      color: XColorUtils.color333333,
                  ),
                padding: XWidgetUtils.getEdgeInsets(0, 60, 0, 0),
              ),
              XWidgetUtils.getLayoutContainer(
                  alignment: Alignment.center,
                  margin: XWidgetUtils.getEdgeInsets(0, 59, 0, 0),
                  child: XWidgetUtils.getLayoutRow(
                      mainAxisSize:MainAxisSize.min,
                      mainAxisAlignment:MainAxisAlignment.center,
                      children: [
                        XWidgetUtils.getWidgetText(
                            '共',
                            style: XStyleUtils.getTextStyle(
                              fontSize: 50,
                              color: XColorUtils.color333333,
                              fontWeight: FontWeight.bold
                            )
                        ),
                        XWidgetUtils.getWidgetText(
                            XNumberUtils.formatDoubleX(RBBusinessUtils.shoppingcartInfo_selfService['totalQuantity']??0, n: 0),
                            style: XStyleUtils.getTextStyle(
                                fontSize: 50,
                                color: const Color(0xFFFF0020),
                                fontWeight: FontWeight.bold
                            )
                        ),
                        XWidgetUtils.getWidgetText(
                            '件，¥${XNumberUtils.formatDoubleX(RBBusinessUtils.shoppingcartInfo_selfService['totalMoney']??0, n: 2)}',
                            style: XStyleUtils.getTextStyle(
                                fontSize: 50,
                                color: XColorUtils.color333333,
                                fontWeight: FontWeight.bold
                            )
                        ),
                      ]
                  )
              ),
              XWidgetUtils.getWidgetTimerButton(
                margin: XWidgetUtils.getEdgeInsets(90, 109, 90, 0),
                  timeout_s: 5,
                  defaultName: isSucceed?'完成交易':'交易结束',
                  fontColor: RBColors.reabamColor4,
                  fontSize: 40,
                  height: 120,
                  borderColor: RBColors.reabamColor4,
                  defaultBackgroundColor:Colors.white,
                  isAutoStart: true,
                  tag_action_receive_notify:RBConfigs.Tag_action_receive_notify_pay_auto_exit,
                  onClick: (r1){
                    finishPage(backToPointPageName:'StatePageSelfServiceHomeIndex');
                  },
                  onTimerComplete: (r1){
                    finishPage(backToPointPageName:'StatePageSelfServiceHomeIndex');
                  }
              ),
              const Spacer(),
              isSucceed?XWidgetUtils.getWidgetText(
                '请取走商品和小票',
                style: XStyleUtils.getTextStyle(
                  fontSize: 40,
                  color: XColorUtils.color333333,
                ),
                padding: XWidgetUtils.getEdgeInsets(0, 0, 0, 82),
              ):XWidgetUtils.getLayoutContainer(),
            ]
        )
    );
  }



  @override
  Future<void> updateData({int pageIndex = 1}) async {

  }

  @override
  void onDestroy() {
    super.onDestroy();
    Future((){
      //清理上传订单(已追平)
      XObjectBoxUtils.checkAndDeleteUploadOrder();
    });
  }


  @override
  Color getXPageBackgroundColor() {
    return Colors.white;
  }


}